<!--
 * @Author: daidai
 * @Date: 2022-02-28 16:16:42
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-07-20 17:57:11
 * @FilePath: \web-pc\src\pages\big-screen\view\indexs\left-center.vue
-->
<template>
  <div class="user_Overview flex flex-wrap" v-if="pageflag">
    <div class="user_Overview-box flex">
      <div class="flex flex-direction align-center">
        <div class="flex align-center">
          <img src="../../assets/img/logo/bed.png" alt="" />
          <span class="num">2613张</span>
        </div>

        <p class="text">养老人数：<span>892</span> 人</p>
      </div>
      <div>
        <div class="flex flex-direction align-center">
          <dv-decoration-9 style="width: 80px; height: 80px" :dur="5"
            >34%</dv-decoration-9
          >
          <span style="margin-top: 8px"> 入住率</span>
        </div>

        <!-- <dv-percent-pond :config="config" style="width: 180px; height: 38px" /> -->
      </div>
    </div>
  </div>
  <Reacquire v-else @onclick="getData" line-height="200px">
    重新获取
  </Reacquire>
</template>

<script>
import { currentGET } from "api/modules";
let style = {
  fontSize: 24,
};
const fullWidth = 300;
const borderGap = 3;
const borderWidth = 3;
const usefulWidth = fullWidth - (borderGap + borderWidth) * 2;

const pieceLength = [0.25, 0.5, 0.25];
const pieceGap = 3;

const lineDash = pieceLength
  .map((l) => [usefulWidth * l, pieceGap])
  .reduce((all, current) => [...all, ...current], []);
export default {
  data() {
    return {
      options: {},
      userOverview: {
        alarmNum: 0,
        offlineNum: 0,
        onlineNum: 0,
        totalNum: 0,
      },
      pageflag: true,
      timer: null,
      config: {
        value: 34,
        colors: ["#01c4f9", "#c135ff"],
        lineDash,
      },
      onlineconfig: {
        number: [0],
        content: "{nt}",
        style: {
          ...style,
          // stroke: "#07f7a8",
          fill: "#07f7a8",
        },
      },
      offlineconfig: {
        number: [0],
        content: "{nt}",
        style: {
          ...style,
          // stroke: "#e3b337",
          fill: "#e3b337",
        },
      },
      laramnumconfig: {
        number: [0],
        content: "{nt}",
        style: {
          ...style,
          // stroke: "#f5023d",
          fill: "#f5023d",
        },
      },
    };
  },
  filters: {
    numsFilter(msg) {
      return msg || 0;
    },
  },
  created() {
    this.getData();
  },
  mounted() {},
  beforeDestroy() {
    this.clearData();
  },
  methods: {
    clearData() {
      if (this.timer) {
        clearInterval(this.timer);
        this.timer = null;
      }
    },
    getData() {
      this.pageflag = true;
      currentGET("big2").then((res) => {
        if (!this.timer) {
          console.log("设备总览", res);
        }
        if (res.success) {
          this.userOverview = res.data;
          this.onlineconfig = {
            ...this.onlineconfig,
            number: [res.data.onlineNum],
          };
          this.config = {
            ...this.config,
            number: [res.data.totalNum],
          };
          this.offlineconfig = {
            ...this.offlineconfig,
            number: [res.data.offlineNum],
          };
          this.laramnumconfig = {
            ...this.laramnumconfig,
            number: [res.data.alarmNum],
          };
          this.switper();
        } else {
          this.pageflag = false;
          this.$Message.warning(res.msg);
        }
      });
    },
    //轮询
    switper() {
      if (this.timer) {
        return;
      }
      let looper = (a) => {
        this.getData();
      };
      this.timer = setInterval(
        looper,
        this.$store.state.setting.echartsAutoTime
      );
    },
  },
};
</script>
<style lang="scss" scoped>
.user_Overview {
  &-item {
    // flex: 1;
    width: 41%;
    height: 92px;
    background: linear-gradient(to right bottom, #060130, transparent);
    margin: 10px 10px 0;
    padding: 20px 10px;
    border-left: #3ea1fd solid 6px;

    p {
      text-align: center;
      height: 16px;
      font-size: 16px;
    }
    .item-left {
      width: 70%;
      .text {
        font-size: 20px;
      }
      .num {
        font-size: 28px;
        margin: 10px 0;
      }
    }

    img {
      width: 40px;
    }

    .user_Overview_nums {
      width: 100px;
      height: 100px;
      text-align: center;
      line-height: 100px;
      font-size: 22px;
      margin: 50px auto 30px;
      background-size: cover;
      background-position: center center;
      position: relative;

      &::before {
        content: "";
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
      }

      &.bgdonghua::before {
        animation: rotating 14s linear infinite;
      }
    }

    .allnum {
      // background-image: url("../../assets/img/left_top_lan.png");
      &::before {
        background-image: url("../../assets/img/left_top_lan.png");
      }
    }

    .online {
      &::before {
        background-image: url("../../assets/img/left_top_lv.png");
      }
    }

    .offline {
      &::before {
        background-image: url("../../assets/img/left_top_huang.png");
      }
    }

    .laramnum {
      &::before {
        background-image: url("../../assets/img/left_top_hong.png");
      }
    }
  }

  &-bottom {
    width: 41%;
    height: 92px;
    margin: 10px 10px 0;
    padding: 20px 10px;
    img {
      width: 30px;
    }
  }

  &-box {
    width: 100%;
    align-items: center;
    justify-content: space-around;
    padding: 10px;
    p {
      font-size: 22px;
      margin-bottom: 5px;
    }
    img {
      width: 48px;
      margin-right: 10px;
    }
    .num {
      font-size: 26px;
      font-weight: 600;
    }
    .text {
      font-size: 16px;
      margin-top: 10px;
      font-weight: 600;
      span {
        font-weight: 600;

        color: aqua;
      }
    }
  }
}
</style>
